<?php

namespace Modules\DataAnalysis\Entities;

use DateTimeInterface;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Video extends Model
{
    use HasFactory;

    /**
     * 不可以批量赋值的属性
     *
     * @var array
     */
    protected $guarded = [];

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
    }

    /**
     * 说明：关联评论
     *
     * @return
     * @param   type
     * @author  daixinguo (daixinguo57@163.com)
     */
    public function comments()
    {
        return $this->hasMany(Comment::class, 'video_id', 'id');
    }

    /**
     * 说明：关联评论分词
     *
     * @return
     * @param   type
     * @author  daixinguo (daixinguo57@163.com)
     */
    public function comment_phrases()
    {
        return $this->hasMany(CommentPhrase::class, 'video_id', 'id');
    }
}
